import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:hx_im_plugin_example/hq_im_ui/pages/chat/hq_chat_page.dart';
import 'package:hx_im_plugin_example/hq_im_ui/pages/contacts/hq_contact_add_friends_page.dart';
import 'package:hx_im_plugin_example/hq_im_ui/pages/contacts/hq_contact_select_page.dart';
import 'package:hx_im_plugin_example/hq_im_ui/pages/conversations/hq_conversations_page.dart';
import 'package:hx_im_plugin_example/hq_im_ui/pages/group/hq_group_info_page.dart';
import 'package:hx_im_plugin/hx_im_plugin.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  SystemUiOverlayStyle uiStyle = SystemUiOverlayStyle.light;
  SystemChrome.setSystemUIOverlayStyle(uiStyle);
  EMPushConfig config = EMPushConfig()..enableAPNs('EaseIM_APNS_Product');
  var options = EMOptions('zyls#lsj-ceshi-im');
  options.pushConfig = config;
  EMClient.getInstance.init(options).then((value) => null);
  return runApp(EaseIMDemo());
}

class EaseIMDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    return ScreenUtilInit(
      designSize: Size(375, 667),
      builder: () {
        return MaterialApp(
          builder: (context, child) => FlutterSmartDialog(child: child),
          debugShowCheckedModeBanner: false,
          onGenerateRoute: onGenerateRoute,
          theme: ThemeData(appBarTheme: AppBarTheme(elevation: 1), buttonTheme: ButtonThemeData(minWidth: 44.0, highlightColor: Color.fromRGBO(0, 0, 0, 0), splashColor: Color.fromRGBO(0, 0, 0, 0)), highlightColor: Color.fromRGBO(0, 0, 0, 0), splashColor: Color.fromRGBO(0, 0, 0, 0)),
          home: HqConversationsPage()
        );
      },
    );
  }
}

Route<dynamic> onGenerateRoute(RouteSettings settings) {
  var routes = <String, WidgetBuilder>{
    // '/login': (context) => LoginPage(),
    // '/register': (context) => RegisterPage(),
    // '/home': (context) => HomePage(),
    // '/friendsRequest': (context) => ContactFirendsRequestPage(),
    '/addFriends': (context) => HqContactAddFriendsPage(),
    // '/publicGroups': (context) => PublicGroupsPage(),
    // '/joinedGroups': (context) => JoinedGroupsPage(),
    '/chat': (context) => HQChatPage(
      (settings.arguments as List)[0],
      (settings.arguments as List)[1],
    ),
    '/groupInfo': (context) => HqGroupInfoPage(settings.arguments),
    // '/groupMemberList': (context) => GroupMembersPage(
    //   (settings.arguments as List)[0],
    //   (settings.arguments as List)[1],
    // ),
    // '/rooms': (context) => ChatroomsListPages(),
    '/contactSelect': (context) => HqContactSelectPage(),
  };
  WidgetBuilder builder = routes[settings.name];
  return MaterialPageRoute(builder: (ctx) => builder(ctx));
}
